package com.example.utilDao;

import android.content.Context;

import androidx.test.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;


import com.example.entiy.Student;

import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.List;

import static org.junit.Assert.*;

@RunWith(AndroidJUnit4.class)
public class AndroidTestStudentDao {

    @Test
    public void studentAdd() {
        //获取上下文
        Context appContext = InstrumentationRegistry.getTargetContext();
        StudentDao dao = new StudentDao(appContext);
        dao.studentAdd("张三","male");
    }

    @Test
    public void studentDelete() {
        //获取上下文
        Context appContext = InstrumentationRegistry.getTargetContext();
        StudentDao dao = new StudentDao(appContext);
        dao.studentDelete("张三");
    }

    @Test
    public void studentUpdate() {
        //获取上下文
        Context appContext = InstrumentationRegistry.getTargetContext();
        StudentDao dao = new StudentDao(appContext);
        dao.studentUpdate("张三","female");

    }

    @Test
    public void studentQueryAll() {
        //获取上下文
        Context appContext = InstrumentationRegistry.getTargetContext();
        StudentDao dao = new StudentDao(appContext);
        List<Student> students = dao.studentQueryAll();
        for(Student student : students)
            System.out.println("姓: "+student.getName()+"    名: "+student.getSex());
    }

    @Test
    public void studentQueryByname() {
        //获取上下文
        Context appContext = InstrumentationRegistry.getTargetContext();
        StudentDao dao = new StudentDao(appContext);
        String str = dao.studentQueryByname("张三");
        System.out.println(str);
    }
}